﻿$(function () {
    doAjax('http://www.64365.com/ajax/UserLogin.aspx', { type: 'loginUser' }, function (json) {
        LoginRegisterTop(json);
    }, 'jsonp', function () { });

    if (window.location.hostname == "user.64365.com") {
        doAjax('http://user.64365.com/ajax/HeadCaseInfo.aspx', { type: 'caseInfo' }, function(result) {
            CaseInfo($(result).find('msg').text());
        }, 'xml', function() {
        });
    }
});

//最近前三条委托案例滚动
function CaseInfo(ret) {
    if (ret) {
        var $ul = $('.t-nav');
        $ul.before(ret);
        $('.law-scroll').groupSwitch({
            derection: 'top',
            content: 'p',
            len: 1,
            perNum: 1,
            auto: true,
            autoSpeed: 3000,
            speed: 1500
        });
    }
}

function LoginRegisterTop(json) {
    var element = $('.g-s').find('.s-nav:last');
    if (json) {
        element.removeClass('none').prev().addClass('none').end().find('.ect').contents().each(function () {
            if (this.nodeType == 3) {
                if (json.ScreenName.countCharacters() >= 9) {
                    var screenName = json.ScreenName.subString(0, 6);
                    if (screenName.length != screenName.countCharacters()) {
                        this.nodeValue = screenName + '...';
                    } else {
                        this.nodeValue = json.ScreenName.substring(0, 5) + '...';
                    }
                } else {
                    this.nodeValue = json.ScreenName;
                }
            }
        });
        if (json.UserType == 1) {
            element.find('.s-oper').children(':first').attr('href', 'http://public.64365.com/').end().next()
                .find('a[href]').first().attr('href', 'http://public.64365.com/question/').each(function () {
                    $(this).find('.i-tip-new').html(json.UnReaded);
                })
                .end().eq(1).attr('href', 'http://public.64365.com/message/?unread=true')
                .end().last().attr('href', 'http://public.64365.com/myinfo/');
        } else if (json.UserType == 2) {
            element.find('.s-oper').children(':first').attr('href', 'http://user.64365.com/').end().next()
                .find('a[href]').first().attr('href', 'http://user.64365.com/question/').each(function () {
                    $(this).find('.i-tip-new').html(json.UnReaded);
                })
                .end().eq(1).attr('href', 'http://user.64365.com/message/?unread=true')
                .end().last().attr('href', 'http://user.64365.com/myinfo/');
        }
        if (json.Message > 0) {
            $('em[name="messageCount"]').show().html(json.Message);
        }
        var msgNumber = 0;
        element.find('.s-u-more').find('.i-tip-new').each(function () {
            msgNumber += parseInt($(this).html());
            if ($(this).html() > 0) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
        element.find('.i-bell').children('.i-tip-new').html(msgNumber).each(function () {
            if ($(this).html() > 0) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
        //lawyer center top 2

    } else {
        element.addClass('none').next().removeClass('none');
    }
}